/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package config;

import config.Models.Conf_BoxEgg;
import config.Models.Conf_BoxEggItem;
import config.Models.Conf_Cote;
import config.Models.Conf_Egg;
import config.Models.Conf_Fish;
import config.Models.Conf_Friend;
import config.Models.Conf_Ibshop_item;
import config.Models.Conf_Item;
import config.Models.Conf_ItemGroup;
import config.Models.Conf_Mix;
import config.Models.Conf_Mix_item;
import config.Models.Conf_Peg;
import config.Models.Conf_User;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import libCore.Util;
import org.cliffc.high_scale_lib.NonBlockingHashMap;

/**
 *
 * @author LinhTA
 */
public class ConfigModels {

    private static Map<String, ConfigModels> _instances = new NonBlockingHashMap();
    private static final Lock createLock_ = new ReentrantLock();
    public static HashMap<String, Conf_Cote> conf_cotes;
    public static HashMap<String, Conf_Peg> conf_pegs;
    public static Conf_Friend conf_friends;
    public static HashMap<String, Conf_BoxEgg> conf_boxEggs;
    public static HashMap<String, Conf_BoxEggItem> conf_boxEgg_item;
    public static HashMap<String, Conf_Egg> conf_eggs;
    public static HashMap<String, Conf_Ibshop_item> conf_ibshopItems;
    public static HashMap<String, Conf_Mix> conf_mixs;
    public static HashMap<String, Conf_Mix_item> conf_mixItems;
    public static HashMap<String, Conf_User> conf_user;
    public static HashMap<String, Conf_Fish> conf_fishs;
    public static HashMap<String, Conf_ItemGroup> conf_itemGroups;
    public static HashMap<String, Conf_Item> conf_items;

    private ConfigModels() {

        conf_boxEggs    =   new HashMap<String, Conf_BoxEgg>();
        conf_cotes      =   new HashMap<String, Conf_Cote>();
        conf_eggs       =   new HashMap<String, Conf_Egg>();
        //conf_friends = new Conf_Friend(null);
        conf_ibshopItems =  new HashMap<String, Conf_Ibshop_item>();
        conf_mixItems   =   new HashMap<String, Conf_Mix_item>();
        conf_mixs       =   new HashMap<String, Conf_Mix>();
        conf_pegs       =   new HashMap<String, Conf_Peg>();
        conf_user       =   new HashMap<String, Conf_User>();
        conf_boxEgg_item = new HashMap<String, Conf_BoxEggItem>();
        conf_fishs      =   new HashMap<String, Conf_Fish>();
        conf_itemGroups =   new HashMap<String, Conf_ItemGroup>();
        conf_items      =   new HashMap<String, Conf_Item>();

        Map<String, Object> config  =   ConfigDB.getConfig();

        setCotes(Util.obj2Map(config.get(ConfigMacros.COTE)));
        setBoxEggs(Util.obj2Map(config.get(ConfigMacros.BOXEGG)));
        setEggs(Util.obj2Map(config.get(ConfigMacros.EGG)));
        setFriends(Util.obj2Map(config.get(ConfigMacros.FRIEND)));
        setIbshopItems(Util.obj2Map(config.get(ConfigMacros.SHOPITEM)));
        setMixItems(Util.obj2Map(config.get(ConfigMacros.MIXITEM)));
        setMixs(Util.obj2Map(config.get(ConfigMacros.MIX)));
        setPegs(Util.obj2Map(config.get(ConfigMacros.PEG)));
        setUsers(Util.obj2Map(config.get(ConfigMacros.USER)));
        setBoxEggItem(Util.obj2Map(config.get(ConfigMacros.BOXEGG_ITEM)));
        setFish(Util.obj2Map(config.get(ConfigMacros.FISH)));
        setItemGroups(Util.obj2Map(config.get(ConfigMacros.ITEM_GROUP)));
        setItems(Util.obj2Map(config.get(ConfigMacros.ITEM)));
    }

    public static ConfigModels getInstance() {
        if (!_instances.containsKey("models")) {
            createLock_.lock();
            try {
                if (_instances.get("models") == null) {
                    _instances.put("models", new ConfigModels());
                }
            } finally {
                createLock_.unlock();
            }
        }
        return _instances.get("models");

    }

    public static void setCotes(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Cote cote = new Conf_Cote(Util.obj2Map(object));

            conf_cotes.put(string, cote);
        }

    }

    public static void setFish(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Fish fish = new Conf_Fish(Util.obj2Map(object));

            conf_fishs.put(string, fish);
        }
    }
    
    public static void setBoxEggItem(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_BoxEggItem cote = new Conf_BoxEggItem(Util.obj2Map(object));

            conf_boxEgg_item.put(string, cote);
        }
    }
    
    public static void setPegs(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Peg peg = new Conf_Peg(Util.obj2Map(object));

            conf_pegs.put(string, peg);
        }
    }

    public static void setFriends(Map<String, Object> obj) {
        conf_friends = new Conf_Friend(obj);
    }

    public static void setBoxEggs(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_BoxEgg boxEgg = new Conf_BoxEgg(Util.obj2Map(object));

            conf_boxEggs.put(string, boxEgg);
        }
    }

    public static void setEggs(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Egg egg = new Conf_Egg(Util.obj2Map(object));

            conf_eggs.put(string, egg);
        }
    }

    public static void setIbshopItems(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Ibshop_item ibshopItem = new Conf_Ibshop_item(Util.obj2Map(object));

            conf_ibshopItems.put(string, ibshopItem);
        }
    }

    public static void setUsers(Map<String, Object> obj) {
        
        Conf_User user = new Conf_User(Util.obj2Map(obj));
        conf_user.put( ConfigMacros.USER, user);
    }

    public static void setMixs(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Mix mix = new Conf_Mix(Util.obj2Map(object));

            conf_mixs.put(string, mix);
        }
    }

    public static void setMixItems(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Mix_item mixItem = new Conf_Mix_item(Util.obj2Map(object));

            conf_mixItems.put(string, mixItem);
        }
    }

    public static void setItemGroups(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_ItemGroup itemGroup = new Conf_ItemGroup(Util.obj2Map(object));

            conf_itemGroups.put(string, itemGroup);
        }
    }

    public static void setItems(Map<String, Object> obj) {
        for (Map.Entry<String, Object> entry : obj.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_Item item = new Conf_Item(Util.obj2Map(object));

            conf_items.put(string, item);
        }
    }

    public Conf_Peg getConfPeg(String pegid) {
        Conf_Peg conf = conf_pegs.get(pegid);

        return conf;
    }

    public Conf_Egg getConfEgg(String eggid) {
        Conf_Egg conf = conf_eggs.get(eggid);

        return conf;
    }

    public static void getDataConfig() {
    }
}
